# match
# case

"""
匹配简单值
"""
# grade = "E"
#
# match grade:
#     case "A":
#         print("优秀")
#     case "B":
#         print("良好")
#     case _:
#         print("不及格")


"""
匹配数据类型
"""
# value = (666, 777, 888)
#
# match value:
#     case str():
#         print("字符串")
#     case int():
#         print("整数")
#     case list():
#         print("列表")
#     case _:
#         print("其他类型")


"""
匹配解构
"""
# value = (10, "你好", "Hello")
#
# match value:
#     case (x, y):
#         print(f"元组，x = {x}, y = {y}")
#     case [x, y, z] if isinstance(value, list):
#         print(f"列表，x = {x}, y = {y}, z = {z}")
#     case _:
#         print("其他类型")


"""
明确匹配类型
"""
# value = {1, 3, "r"}
#
# if isinstance(value, tuple):
#     match value:
#         case (x, y, z):
#             print(f"元组，x = {x}, y = {y}, z = {z}")
#         case _:
#             print("其他类型")
#
# elif isinstance(value, list):
#     match value:
#         case [x, y, z]:
#             print(f"列表，x = {x}, y = {y}, z = {z}")
#         case _:
#             print("其他类型")
# else:
#     print("其他类型")


"""
结合条件匹配
"""
# value = 0
#
# match value:
#     case x if x > 0:
#         print("正数")
#     case x if x < 0:
#         print("负数")
#     case _:
#         print("零")


"""
匹配字典
"""
value = {"name": "张三", "age": 18, "gender": "男"}

match value:
    case {"age": age, "name": name, "gender": gender}:
        print(f"姓名：{name}, 年龄：{age}, 性别：{gender}")
    case {"name": name, "age": age}:
        print(f"姓名：{name}, 年龄：{age}")
    case _:
        print("其他类型")


